package com.xbongbong.formula.qlexpress.operator.text;

import com.ql.util.express.Operator;
import org.apache.commons.codec.binary.Base64;

/**
 * @author: chy
 * @date: 2018/7/5 15:22
 * @desrcption: 将文本字符串进行BASE64加密
 */
public class OperatorBase64 extends Operator {

    public OperatorBase64(String name){
        this.name = name;
    }

    public OperatorBase64(String aliasName, String name, String errorInfo){
        this.aliasName = aliasName;
        this.name = name;
        this.errorInfo = errorInfo;
    }

    /**
     *
     * @param list
     * @return
     * example： String str = "BASE64(\"2018\")";
     * @throws Exception
     */
    @Override
    public Object executeInner(Object[] list) throws Exception {
        Base64 base64 = new Base64();
        return base64.encodeToString(list[0].toString().getBytes());
    }
}
